﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MDS
{
    public class StockExchange : EnumBase<char>
    {

        private StockExchange(char id) : base(id) { }
        private static Dictionary<char, StockExchange> _allExchanges;

        static StockExchange()
        {

            HuA = new StockExchange('0');
            ShenA = new StockExchange('1');
            HuB = new StockExchange('2');
            ShenB = new StockExchange('3');

            _allExchanges = new Dictionary<char, StockExchange>();
            _allExchanges.Add(HuA._value, HuA);
            _allExchanges.Add(HuB._value, HuB);
            _allExchanges.Add(ShenA._value, ShenA);
            _allExchanges.Add(ShenB._value, ShenB);

        }

        public static bool TryParse(char exchId, out StockExchange exchange)
        {
            if (_allExchanges.ContainsKey(exchId))
            {
                exchange = _allExchanges[exchId];
                return true;
            }
            else
            {
                exchange = default(StockExchange);
                return false;
            }
        }
        public static bool TryParse(string exchIdStr, out StockExchange exchange)
        {
            if (!string.IsNullOrEmpty(exchIdStr))
            {
                char exchId = exchIdStr[0];
                return TryParse(exchId, out exchange);
            }
            else
            {
                exchange = default(StockExchange);
                return false;
            }

        }
        public static StockExchange HuA { get; private set; }
        public static StockExchange ShenA { get; private set; }
        public static StockExchange HuB { get; private set; }
        public static StockExchange ShenB { get; private set; }
    }
}
